﻿using AutoMapper;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Xyz.Core.Data;
using System.Linq;
using Xyz.Core.Infrastructure;
using Xyz.Core.Infrastructure.Extentions;
using Xyz.Core.Interfaces;
using Xyz.Core.Models;
using Xyz.Core.Models.Filters;

namespace Xyz.Core.Services.AppServices
{
    public class AcService : IAcService
    {
        private readonly FlightContext _context;
        private readonly IMapper _mapper;

        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="context"></param>
        /// <param name="mapper"></param>
        public AcService(FlightContext context, IMapper mapper)
        {
            _mapper = mapper;
            _context = context;
        }

        public async Task<PagedResult<AcDto>> SearchAsync(AcFilters filters)
        {
            if (filters == null)
                return new PagedResult<AcDto>(1, 0);
            // var query = _context.Hbxxs.Where(item => !item.IsDeleted);
            var query = from s in _context.Acs
                        select s;

            if (filters.keywords.IsNotBlank())
                query = query.Where(s => s.Acs.Contains(filters.keywords));

            //return view();
            return await query.OrderByDescending(item => item.Id)
              .Select(item => new AcDto
              {
                  Id = item.Id,
                  //  Icaoid = item.Icaoid,
                  // Elevation = item.Elevation,
                  Acs = item.Acs
              }).PagingAsync(filters.page, filters.rows);
        }
    }
}
